package com.pushmsg.wappush;

public class WapPushBody
{
	private final byte wbxml = 0x02;
	private final byte sipi = 0x05;
	private final byte charset = 0x6A;
	private final byte strtbllen = 0x00;
	private final byte si = 0x45; //si with content
	private final byte indication = (byte)0xC6; //indication with content and attribute
	private final byte hrefattr = 0x0C; //href=http://
	private final byte actionattr = 0x08; //action=signal
	private final byte siidattr = 0x11;

	private final byte inlinestr = 0x03;
	private final byte inlinestrend = 0x00;
	private final byte endelement = 0x01;


	private String url;
	private String siid;
	private String message;

	public WapPushBody(String val1, String val2, String val3)
	{
		siid = val1;
		url = val2;
		message = val3;
	}

	protected void setSiid(String val)
	{
		siid = val;
	}

	protected void setUrl(String val)
	{
		url = val;
	}

	protected void setMessage(String val)
	{
		message = val;
	}

	protected int getLength()
	{
		return 18 + siid.length() + url.length() + message.length();
	}

	protected byte[] getData()
	{
		byte[] data = new byte[getLength()];
		byte[] temp;
		int i, ndx=0;

		data[ndx++] = wbxml;
		data[ndx++] = sipi;
		data[ndx++] = charset;
		data[ndx++] = strtbllen;
		data[ndx++] = si;
		data[ndx++] = indication;
		data[ndx++] = hrefattr;
		data[ndx++] = inlinestr;

		temp = url.getBytes();
		for(i=0; i<temp.length; i++)
		{
			data[ndx++] = temp[i];
		}
		data[ndx++] = inlinestrend;
		data[ndx++] = siidattr;
		data[ndx++] = inlinestr;

		temp = siid.getBytes();
		for(i=0; i<siid.length(); i++)
		{
			data[ndx++] = temp[i];
		}
		data[ndx++] = inlinestrend;
		data[ndx++] = actionattr;
		data[ndx++] = endelement;
		data[ndx++] = inlinestr;

		temp = message.getBytes();
		for(i=0; i<message.length(); i++)
		{
			data[ndx++] = temp[i];
		}

		data[ndx++] = inlinestrend;
		data[ndx++] = endelement;
		data[ndx++] = endelement;

		return data;
	}

}